package com.zhaojd.framework.controller;

import com.zhaojd.framework.model.SysDict;
import com.zhaojd.framework.service.IDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * create by zhoajd on 2018-03-15
 * SpringMVC环境测试controller
 */
@Controller
public class HomeController {

    private final IDictService dictService;

    @Autowired
    public HomeController(IDictService dictService) {
        this.dictService = dictService;
    }

    /**
     * 页面跳转测试
     * @return
     */
    @GetMapping("/homePage")
    public String homePage() {
        return "home";
    }

    @ResponseBody
    @GetMapping("/home")
    public Map<String, Object> home() {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("key", "SpringMVC test");
        return result;
    }

    @ResponseBody
    @GetMapping("/testMyBatis")
    public Map<String, String> testMyBatis() {
        Map<String, String> result = new HashMap<String, String>();
        SysDict sysDict = dictService.findById(6);
        result.put("id",sysDict.getId().toString());
        result.put("name",sysDict.getName());
        result.put("code",sysDict.getCode());
        return result;
    }
}
